

var personPrice = $(".personPrice").val()
var time = new Date();
var year = time.getFullYear(); //获取完整的年份(4位,1970-???)

var month = time.getMonth()+1; //获取当前月份(0-11,0代表1月)

var date = time.getDate(); //获取当前日(1-31)

// <!--=============================时间格式转换========================-->
function getDate(date){
    var date = new Date(date);
    var month = date.getMonth()+1;
    var day = date.getDate();
    return month+"-"+day
}

var ym;
if(month<10){
    ym = year+"年0"+month+"月";
}
if(month>=10){
    ym = year+"年"+month+"月";
}
$(".ym").text(ym)


var t1 = $(".t1");
for (var i=1;i<=7;i++){
    var md = getDate(new Date().setDate(i));
    var m = md.split("-")[0];
    var d = md.split("-")[1];
    if(m==month && d<=date  || m>month){
        if(d==date){
            d="今天";
        }
        var td ="<td>\n" +
            "                                    <div class=\"disable disable normal\">\n" +
            "                                        "+d+"\n" +
            "\n" +
            "                                    </div>\n" +
            "                                </td>"

        t1.append(td)
    }
    if(m==month && d>date){
        var td ="<td>\n" +
            "                                    <div class=\"normal\" id=\"day1\">\n" +
            "                                    <span>    "+d+"</span>\n" +
            "                                        <p class=\"price\">¥"+personPrice+"</p>\n" +
            "\n" +
            "                                </td>"

        t1.append(td)
    }
}
var t2 = $(".t2");
for (var i=8;i<=14;i++){
    var md = getDate(new Date().setDate(i));
    var m = md.split("-")[0];
    var d = md.split("-")[1];
    if(m==month && d<=date  || m>month){
        if(d==date){
            d="今天";
        }
        var td ="<td>\n" +
            "                                    <div class=\"disable disable normal\">\n" +
            "                                        "+d+"\n" +
            "\n" +
            "                                    </div>\n" +
            "                                </td>"

        t2.append(td)
    }
    if(m==month && d>date){
        var td ="<td>\n" +
            "                                    <div class=\"normal\" id=\"day1\">\n" +
            "                                    <span>    "+d+"</span>\n" +
            "                                        <p class=\"price\">¥"+personPrice+"</p>\n" +
            "\n" +
            "                                </td>"

        t2.append(td)
    }
}
var t3 = $(".t3");
for (var i=15;i<=21;i++){
    var md = getDate(new Date().setDate(i));
    var m = md.split("-")[0];
    var d = md.split("-")[1];
    if(m==month && d<=date  || m>month){
        if(d==date){
            d="今天";
        }
        var td ="<td>\n" +
            "                                    <div class=\"disable disable normal\">\n" +
            "                                        "+d+"\n" +
            "\n" +
            "                                    </div>\n" +
            "                                </td>"

        t3.append(td)
    }
    if(m==month && d>date){
        var td ="<td>\n" +
            "                                    <div class=\"normal\" id=\"day1\">\n" +
            "                                    <span>    "+d+"</span>\n" +
            "                                        <p class=\"price\">¥"+personPrice+"</p>\n" +
            "\n" +
            "                                </td>"

        t3.append(td)
    }
}
var t4 = $(".t4");
for (var i=22;i<=28;i++){
    var md = getDate(new Date().setDate(i));
    var m = md.split("-")[0];
    var d = md.split("-")[1];
    if(m==month && d<=date  || m>month){
        if(d==date){
            d="今天";
        }
        var td ="<td>\n" +
            "                                    <div class=\"disable disable normal\">\n" +
            "                                        "+d+"\n" +
            "\n" +
            "                                    </div>\n" +
            "                                </td>"

        t4.append(td)
    }
    if(m==month && d>date){
        var td ="<td>\n" +
            "                                    <div class=\"normal\" id=\"day1\">\n" +
            "                                    <span>    "+d+"</span>\n" +
            "                                        <p class=\"price\">¥"+personPrice+"</p>\n" +
            "\n" +
            "                                </td>"

        t4.append(td)
    }
}
var t5 = $(".t5");
for (var i=29;i<=35;i++){
    var md = getDate(new Date().setDate(i));
    var m = md.split("-")[0];
    var d = md.split("-")[1];
    if(m==month && d<=date  || m>month){
        if(d==date){
            d="今天";
        }
        var td ="<td>\n" +
            "                                    <div class=\"disable disable normal\">\n" +
            "                                        "+d+"\n" +
            "\n" +
            "                                    </div>\n" +
            "                                </td>"

        t5.append(td)
    }
    if(m==month && d>date){
        var td ="<td>\n" +
            "                                    <div class=\"normal\" id=\"day1\">\n" +
            "                                    <span>    "+d+"</span>\n" +
            "                                        <p class=\"price\">¥"+personPrice+"</p>\n" +
            "\n" +
            "                                </td>"

        t5.append(td)
    }
}
var t6 = $(".t6");
for (var i=36;i<=42;i++){
    var md = getDate(new Date().setDate(i));
    var m = md.split("-")[0];
    var d = md.split("-")[1];
    if(m==month && d<=date || m>month){
        if(d==date){
            d="今天";
        }
        var td ="<td>\n" +
            "                                    <div class=\"disable disable normal\">\n" +
            "                                        "+d+"\n" +
            "\n" +
            "                                    </div>\n" +
            "                                </td>"

        t6.append(td)
    }
    if(m == month && d>date){
        var td ="<td>\n" +
            "                                    <div class=\"normal\" id=\"day1\">\n" +
            "                                    <span>    "+d+"</span>\n" +
            "                                        <p class=\"price\">¥"+personPrice+"</p>\n" +
            "\n" +
            "                                </td>"

        t6.append(td)
    }
}


var nextDate = new Date(time.getTime()+24*60*60*1000); //后一天
console.log(ChangeDateFormat(nextDate))

/*<!--=============================初始化赋值========================-->*/
$(".flightinput").val(ChangeDateFormat(nextDate))
$(".js-start-date").text($(".flightinput").val())
$(".js-end-date").text(getDateFromCurrentDate($(".js-start-date").text(),2))


var calendarContainer= document.querySelector(".calendar");
calendarContainer.onclick =   function(event) {
    var ele = event.target;
    console.log(ele);
    console.log(ele.nodeName);
    console.log(ele.className)
    if(ele.nodeName == 'SPAN' ){
        console.log(ele.innerText);
        var date = year+"/"+month+"/"+ele.innerText;

        $(".flightinput").val(ChangeDateFormat(date))
        $(".js-start-date").text($(".flightinput").val())
        $(".js-end-date").text(getDateFromCurrentDate($(".js-start-date").text(),2))
    }
}




<!--=============================时间格式转换========================-->

function ChangeDateFormat(date) {
    var date = new Date(date);
    var year = date.getFullYear();
    var month = date.getMonth()+1;
    var day = date.getDate();
    var hour = date.getHours();
    var minute = date.getMinutes();
    var second = date.getSeconds();
    return year + "-" + formatTen(month) + "-" + formatTen(day);
}

//fromDate是"yyyy-MM-dd"的日期格式，为指定日期，例如‘2014-10-10’

//dayInterval表示间隔天数，间隔天数大于0，则得到比指定日期大dayInterval天的日期，
// 间隔天数小于0，则得到比指定日期小dayInterval天的日期

function getDateFromCurrentDate(fromDate,dayInterval){

    var curDate = new Date(Date.parse(fromDate.replace(/-/g,"/")));
    curDate.setDate(curDate.getDate()+dayInterval);
    var year = curDate.getFullYear();
    var month = (curDate.getMonth()+1)<10?"0"+(curDate.getMonth()+1):(curDate.getMonth()+1);
    var day = curDate.getDate()<10?"0"+curDate.getDate():curDate.getDate();
    return year+"-"+month+"-"+day;
};

function formatTen(num) {
    return num > 9 ? (num):("0"+num);
}


